<template>
  <div class="goodesmodelbox">
    <el-dialog
      :showClose="false"
      title="活动链接"
      :visible.sync="centerDialogVisible"
      height="30%"
      center
      width="30%"
    >
      <div style="font-size: 30px; font-weight: bold">
        <div>PC端活动路径：</div>
        <div>
          <button
            @click="goPage"
            style="
              width: 100%;
              font-size: 25px;
              border: none;
              background-color: white;
              cursor: pointer;
              color: #4c5bfe;
            "
            type="text"
          >
            {{ this.srcLink }}
          </button>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelgoodesmodel">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { StatisticInfo } from "@/api/mallApi/managementend/marketing";

export default {
  name: "Statistic",
  components: {},
  props: {
    centerDialogVisible: Boolean,
    currentRow: Object,
    enterType: Number,
    cancelSubmit: Number,
  },
  data() {
    return {
      goodsName: "",
      loading: false,
      goodsList: [],
      currentPage: 1, // 分页
      total: 0,
      pageSize: 10,
      centerDialogVisible2: false,
      enterType2: 0,
      mallName: "",
      srcLink: "",
    };
  },
  methods: {
    goPage() {
      const copyText = this.srcLink;

      const textarea = document.createElement("textarea");
      textarea.value = copyText;
      textarea.setAttribute("readonly", "");
      textarea.style.position = "absolute";
      textarea.style.left = "-9999px";
      document.body.appendChild(textarea);

      textarea.select();
      document.execCommand("copy");

      document.body.removeChild(textarea);
      this.$message.success("链接复制成功");
    },
    cancelgoodesmodel2() {
      this.enterType2 = 0;
      this.centerDialogVisible2 = false;
    },
    clearHandle() {
      this.getGoodsListHandle();
    },
    RefreshHandle() {
      this.getGoodsListHandle();
    },
    handleSearch() {
      this.currentPage = 1;
      this.getGoodsListHandle();
    },
    saveActiveHandle() {},
    cancelgoodesmodel() {
      this.$emit("cancelgoodesmodel", false);
    }, // 取消按钮 传值
    getGoodsListHandle() {
      this.loading = true;
      const params = {
        pageNo: this.currentPage,
        pageSize: this.pageSize,
        activeId: this.currentRow.id,
        goodsName: this.goodsName,
        mallName: this.mallName,
      };
      StatisticInfo(params)
        .then((res) => {
          if (res.code !== "00000") return;
          this.goodsList = res.data.rows;
          this.total = parseInt(res.data.totalRows);
          this.loading = false;
        })
        .catch((error) => {
          this.loading = false;
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getGoodsListHandle();
    },
    handleCurrentChange(val) {
      // 分页
      this.currentPage = val;
      this.getGoodsListHandle();
    },
  },
  mounted() {},
  created() {
    this.getGoodsListHandle();
    // this.srcLink = `${process.env.VUE_APP_TARGET}mall/activepage?activityId=${this.currentRow.id}`;
    if (this.enterType === 9) {
      this.srcLink = `http://localhost:9528/mall/falshactivepage?activityId=${this.currentRow.id}`;
    } else {
      this.srcLink = `http://localhost:9528/mall/activepage?activityId=${this.currentRow.id}`;
    }
  },
  watch: {
    centerDialogVisible(newVal) {
      // 监听 centerDialogVisible 的变化
      if (!newVal) {
        // 当 centerDialogVisible 变为 false 时触发事件
        this.$emit("close-dialog");
      }
    },
  },
};
</script>

<style lang="scss">
.goodesmodelbox {
}
</style>
